#######################################
######Masculinity Threat Analysis######
#######################################
###############10/21/25##################
#######################################

####Analysis Script for Gothreau & Haas, forthcoming in Journal of Experimental Political Science###
####A Replication and Extension of Willer et al. (2013) Overdoing Gender: A Test of the Masculine Overcompensation Thesis###

library(haven)
library(ggplot2)
library(dplyr)
library(broom)
library(officer)
library(flextable)
library(forcats)
library(psych)
library(survey)
library(stargazer)
library(purrr)
library(tidyr)
library(forcats)

#Set Working Directory#
MTData <- read.csv("CleanMTData.csv")

###Recode factual manipulation check 
MTData$passedfactcheck <- ifelse(MTData$MANIPULATIONCHECK == 2, 1, 0)

#Create datasets by gender
Data_female <- subset(MTData, gender_binary == "Women")
Data_male <- subset(MTData, gender_binary == "Men")

# Set "no threat" as the reference level
MTData <- MTData %>%
  mutate(P_EXP = fct_relevel(factor(P_EXP), "no threat"))

# Now create the gender-specific datasets (drop unused levels)
Data_female <- MTData %>% filter(gender_binary == "Women") %>% droplevels()
Data_male   <- MTData %>% filter(gender_binary == "Men")   %>% droplevels()

####ROBUSTNESS- interaction between treatment groups and FMC 

#FEMALE models
M1_f <- lm(IRAQ_WAR_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M2_f <- lm(GAY_RIGHT_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5 + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M3_f <- lm(SUV_DESIRABILITY_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M4_f <- lm(SUV_PAY_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M5_f <- lm(DOMINANCE_scale ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M6_f <- lm(SYSTEM_JUSTIFICATION_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M7_f <- lm(CONSERVATISM_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M8_f <- lm(IMMIGRATION_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M9_f <- lm(MARIJUANA_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M10_f <- lm(ELECTRIC_CAR_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M11_f <- lm(TRANS_RIGHT_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M12_f <- lm(HIRINGPOLICY_WOMEN_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)

#MALE models
M1_m <- lm(IRAQ_WAR_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M2_m <- lm(GAY_RIGHT_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M3_m <- lm(SUV_DESIRABILITY_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M4_m <- lm(SUV_PAY_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M5_m <- lm(DOMINANCE_scale ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M6_m <- lm(SYSTEM_JUSTIFICATION_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M7_m <- lm(CONSERVATISM_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M8_m <- lm(IMMIGRATION_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M9_m <- lm(MARIJUANA_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M10_m <- lm(ELECTRIC_CAR_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M11_m <- lm(TRANS_RIGHT_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M12_m <- lm(HIRINGPOLICY_WOMEN_rescaled ~P_EXP*passedfactcheck + AGE + IDEO + EDUC5, data = Data_male, weights = WEIGHT)

#Export to Word document 
# === FEMALE TABLE ===
stargazer(M1_f, M2_f, M3_f, M4_f, M5_f, M6_f,
          type = "html",
          out = "factcheck_female.html",
          title = "Regression Results: Female Respondents")

stargazer(M7_f, M8_f, M9_f, M10_f, M11_f, M12_f,
          type = "html",
          out = "factcheck_female_2.html",
          title = "Regression Results: Female Respondents")

stargazer(M1_m, M2_m, M3_m, M4_m, M5_m, M6_m,
          type = "html",
          out = "factcheck_male.html",
          title = "Regression Results: Male Respondents")

stargazer(M7_m, M8_m, M9_m, M10_m, M11_m, M12_m,
          type = "html",
          out = "factcheck_male_2.html",
          title = "Regression Results: Male Respondents")

######T-tests without survey weights 

dvs <- c(
  "IRAQ_WAR_rescaled", "GAY_RIGHT_rescaled", "SUV_DESIRABILITY_rescaled", "SUV_PAY_rescaled",
  "SYSTEM_JUSTIFICATION_rescaled", "DOMINANCE_scale", "TRADITIONALISM_scale",
  "CONSERVATISM_rescaled", "IMMIGRATION_rescaled", "MARIJUANA_rescaled",
  "ELECTRIC_CAR_rescaled", "TRANS_RIGHT_rescaled", "HIRINGPOLICY_WOMEN_rescaled"
)

# Your comparison function
run_ttests <- function(data, dv_list, group_var = "P_EXP", ref_group = "no threat") {
  conditions <- setdiff(unique(data[[group_var]]), ref_group)
  results <- list()
  
  for (dv in dv_list) {
    for (cond in conditions) {
      df <- data %>%
        filter(.data[[group_var]] %in% c(ref_group, cond)) %>%
        select(all_of(group_var), all_of(dv)) %>%
        drop_na()
      
      df[[group_var]] <- factor(df[[group_var]], levels = c(ref_group, cond))
      
      if (nrow(df) < 3) next
      
      test <- t.test(as.formula(paste(dv, "~", group_var)), data = df)
      
      results[[paste(dv, cond, sep = "_vs_")]] <- tidy(test) %>%
        mutate(
          dv = dv,
          comparison = cond
        )
    }
  }
  
  bind_rows(results)
}

# Run t-tests by gender
ttest_results_female <- run_ttests(Data_female, dvs)
ttest_results_male <- run_ttests(Data_male, dvs)

ttest_results_female <- ttest_results_female %>% mutate(gender = "Women")
ttest_results_male <- ttest_results_male %>% mutate(gender = "Men")

ttest_results_by_gender <- bind_rows(ttest_results_female, ttest_results_male)

ttest_summary_all <- ttest_results_by_gender %>%
  mutate(
    stat_p = paste0("t = ", round(statistic, 2), ", p = ", sprintf("%.3f", p.value))
  ) %>%
  select(dv, comparison, gender, stat_p) %>%
  rename(DV = dv, Gender = gender) %>%
  pivot_wider(names_from = comparison, values_from = stat_p, names_prefix = "t_p_")


###Table 

#Compute group means
mean_table <- function(data, dvs) {
  means <- lapply(dvs, function(dv) {
    data %>%
      group_by(P_EXP) %>%
      summarise(mean_val = mean(.data[[dv]], na.rm = TRUE), .groups = "drop") %>%
      pivot_wider(names_from = P_EXP, values_from = mean_val) %>%
      mutate(DV = dv)
  }) %>%
    bind_rows()
  
  means %>%
    select(DV, `no threat`, threat, constrained, PCKT)
}

means_female <- mean_table(Data_female, dvs) %>% mutate(Gender = "Women")
means_male <- mean_table(Data_male, dvs) %>% mutate(Gender = "Men")

means_combined <- bind_rows(means_female, means_male)

summary_table_all <- means_combined %>%
  left_join(ttest_summary_all, by = c("DV", "Gender")) %>%
  select(Gender, DV, `no threat`, threat, constrained, PCKT,
         t_p_threat, t_p_constrained, t_p_PCKT)

summary_table_compact <- summary_table_all %>%
  select(Gender, DV, t_p_threat, t_p_constrained, t_p_PCKT)

#Filter t-tests for just "threat vs no threat"
ttest_summary <- ttest_results_by_gender %>%
  filter(comparison == "threat") %>%
  mutate(
    stat_p = paste0("t = ", round(statistic, 2), ", p = ", sprintf("%.3f", p.value))
  ) %>%
  select(dv, gender, stat_p) %>%
  rename(DV = dv, Gender = gender)

#Join with mean table
summary_table <- means_combined %>%
  left_join(ttest_summary, by = c("DV", "Gender")) %>%
  select(Gender, DV, `no threat`, threat, constrained, PCKT, stat_p)

ft <- flextable(summary_table_compact) %>%
  set_header_labels(
    Gender = "Gender",
    DV = "Outcome",
    t_p_threat = "Threat vs. No Threat",
    t_p_constrained = "Constrained vs. No Threat",
    t_p_PCKT = "PCKT vs. No Threat"
  ) %>%
  width(j = "Gender", width = 1.0) %>%
  width(j = "DV", width = 1.6) %>%
  width(j = c("t_p_threat", "t_p_constrained", "t_p_PCKT"), width = 2.0) %>%
  set_table_properties(layout = "autofit", width = .95) %>%
  flextable::align(part = "all", align = "center") %>%
  autofit() %>%
  add_footer_lines("* t-tests are unweighted; p-values unadjusted")

doc <- read_docx()
doc <- body_add_par(doc, "T-Test Results by Gender and Experimental Condition", style = "heading 1")
doc <- body_add_flextable(doc, ft)
print(doc, target = "TTest_unweighted.docx")

#####Age Moderation######

#Regression Models with interactions 

M__1 <- lm(IRAQ_WAR_rescaled ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__2 <- lm(GAY_RIGHT_rescaled ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__3 <- lm(SUV_DESIRABILITY_rescaled ~ P_EXP + P_EXP*AGE + gender_binary + AGE + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__4 <- lm(SUV_PAY_rescaled ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__5 <- lm(DOMINANCE_scale ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__6 <- lm(SYSTEM_JUSTIFICATION_rescaled  ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__7 <- lm(CONSERVATISM_rescaled ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__8 <- lm(IMMIGRATION_rescaled  ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__9 <- lm(MARIJUANA_rescaled  ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__10 <- lm(ELECTRIC_CAR_rescaled  ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__11 <- lm(TRANS_RIGHT_rescaled ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)
M__12 <- lm(HIRINGPOLICY_WOMEN_rescaled ~ P_EXP + P_EXP*AGE + AGE + gender_binary + IDEO + EDUC5, data=MTData, weights = WEIGHT)

#Export to Word document 
stargazer(M__1, M__2, M__3, M__4, M__5, M__6,
          type = "html",                      
          out = "regression_results_agemod.html",    
          title = "Regression Results by Outcome Variable",
          dep.var.labels = c("Iraq War", "Gay Rights", "SUV Desirability", "SUV Payment",
                             "Dominance", "System Justification", "Conservatism",
                             "Immigration", "Marijuana", "Electric Car",
                             "Trans Rights", "Hiring Policy (Women)"),
          omit.stat = c("f", "ser"),  
          align = TRUE,
          no.space = TRUE,
          single.row = TRUE)

#Export to Word document 
stargazer(M__7, M__8, M__9, M__10, M__11, M__12,
          type = "html",                      
          out = "regression_results_agemod2.html",    
          title = "Regression Results by Outcome Variable",
          dep.var.labels = c("Iraq War", "Gay Rights", "SUV Desirability", "SUV Payment",
                             "Dominance", "System Justification", "Conservatism",
                             "Immigration", "Marijuana", "Electric Car",
                             "Trans Rights", "Hiring Policy (Women)"),
          omit.stat = c("f", "ser"),  
          align = TRUE,
          no.space = TRUE,
          single.row = TRUE)

####ROBUSTNESS- interaction between treatment groups and actual BSRI score 

#FEMALE models
M1_fbem <- lm(IRAQ_WAR_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M2_fbem <- lm(GAY_RIGHT_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5 + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M3_fbem <- lm(SUV_DESIRABILITY_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M4_fbem <- lm(SUV_PAY_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M5_fbem <- lm(DOMINANCE_scale ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M6_fbem <- lm(SYSTEM_JUSTIFICATION_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M7_fbem <- lm(CONSERVATISM_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M8_fbem <- lm(IMMIGRATION_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M9_fbem <- lm(MARIJUANA_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M10_fbem <- lm(ELECTRIC_CAR_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M11_fbem <- lm(TRANS_RIGHT_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)
M12_fbem <- lm(HIRINGPOLICY_WOMEN_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_female, weights = WEIGHT)

#MALE models
M1_mbem <- lm(IRAQ_WAR_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M2_mbem <- lm(GAY_RIGHT_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M3_mbem <- lm(SUV_DESIRABILITY_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M4_mbem <- lm(SUV_PAY_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M5_mbem <- lm(DOMINANCE_scale ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M6_mbem <- lm(SYSTEM_JUSTIFICATION_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M7_mbem <- lm(CONSERVATISM_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M8_mbem <- lm(IMMIGRATION_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M9_mbem <- lm(MARIJUANA_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M10_mbem <- lm(ELECTRIC_CAR_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M11_mbem <- lm(TRANS_RIGHT_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M12_mbem <- lm(HIRINGPOLICY_WOMEN_rescaled ~P_EXP*ActualBEM + AGE + IDEO + EDUC5, data = Data_male, weights = WEIGHT)

#Export to Word document 
# === FEMALE TABLE ===
stargazer(M1_fbem, M2_fbem, M3_fbem, M4_fbem, M5_fbem, M6_fbem,
          type = "html",
          out = "bem_female.html",
          title = "Regression Results: Female Respondents")

stargazer(M7_fbem, M8_fbem, M9_fbem, M10_fbem, M11_fbem, M12_fbem,
          type = "html",
          out = "bem_female_2.html",
          title = "Regression Results: Female Respondents")

stargazer(M1_mbem, M2_mbem, M3_mbem, M4_mbem, M5_mbem, M6_mbem,
          type = "html",
          out = "bem_male.html",
          title = "Regression Results: Male Respondents")

stargazer(M7_mbem, M8_mbem, M9_mbem, M10_mbem, M11_mbem, M12_mbem,
          type = "html",
          out = "bem_male_2.html",
          title = "Regression Results: Male Respondents")

####ROBUSTNESS- slow/fast responders 
#excluding individuals who recorded either very slow (twice the median time) 
#or fast (less than half the median time) survey durations. 

#median duration=8 minutes 

# Calculate median duration (excluding NAs)
med_time <- median(MTData$duration, na.rm = TRUE)

# Define thresholds
min_time <- 0.5 * med_time
max_time <- 2 * med_time

# Filter data to keep only "reasonable" duration values
MTData_filtered <- MTData %>%
  filter(duration >= min_time & duration <= max_time)

#Create datasets by gender
Data_female_filtered <- subset(MTData_filtered, gender_binary == "Women")
Data_male_filtered <- subset(MTData_filtered, gender_binary == "Men")

#Make "no threat" reference condition
Data_female_filtered$P_EXP <- relevel(Data_female_filtered$P_EXP, ref = "no threat")
Data_male_filtered$P_EXP<- relevel(Data_male_filtered$P_EXP, ref = "no threat")
MTData_filtered$P_EXP<- relevel(MTData_filtered$P_EXP, ref = "no threat")

#FEMALE models
M1_ftime <- lm(IRAQ_WAR_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M2_ftime <- lm(GAY_RIGHT_rescaled ~P_EXP + AGE + IDEO + EDUC5 + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M3_ftime <- lm(SUV_DESIRABILITY_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M4_ftime <- lm(SUV_PAY_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M5_ftime <- lm(DOMINANCE_scale ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M6_ftime <- lm(SYSTEM_JUSTIFICATION_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M7_ftime <- lm(CONSERVATISM_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M8_ftime <- lm(IMMIGRATION_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M9_ftime <- lm(MARIJUANA_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M10_ftime <- lm(ELECTRIC_CAR_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M11_ftime <- lm(TRANS_RIGHT_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)
M12_ftime <- lm(HIRINGPOLICY_WOMEN_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_female_filtered, weights = WEIGHT)

#MALE models
M1_mfiltered <- lm(IRAQ_WAR_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M2_mfiltered <- lm(GAY_RIGHT_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M3_mfiltered <- lm(SUV_DESIRABILITY_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M4_mfiltered <- lm(SUV_PAY_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M5_mfiltered <- lm(DOMINANCE_scale ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M6_mfiltered <- lm(SYSTEM_JUSTIFICATION_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M7_mfiltered <- lm(CONSERVATISM_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M8_mfiltered <- lm(IMMIGRATION_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M9_mfiltered <- lm(MARIJUANA_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M10_mfiltered <- lm(ELECTRIC_CAR_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M11_mfiltered <- lm(TRANS_RIGHT_rescaled ~P_EXP + AGE + IDEO + EDUC5,data = Data_male, weights = WEIGHT)
M12_mfiltered <- lm(HIRINGPOLICY_WOMEN_rescaled ~P_EXP + AGE + IDEO + EDUC5, data = Data_male, weights = WEIGHT)

#Export to Word document 
# === FEMALE TABLE ===
stargazer(M1_ftime, M2_ftime, M3_ftime, M4_ftime, M5_ftime, M6_ftime,
          type = "html",
          out = "time_female.html",
          title = "Regression Results: Female Respondents")

stargazer(M7_ftime, M8_ftime, M9_ftime, M10_ftime, M11_ftime, M12_ftime,
          type = "html",
          out = "time_female_2.html",
          title = "Regression Results: Female Respondents")

stargazer(M1_mfiltered, M2_mfiltered, M3_mfiltered, M4_mfiltered,
          type = "html",
          out = "time_male.html",
          title = "Regression Results: Male Respondents")

stargazer(M5_mfiltered, M6_mfiltered, M7_mfiltered, M8_mfiltered,
          type = "html",
          out = "time_male_2.html",
          title = "Regression Results: Male Respondents")

stargazer(M9_mfiltered, M10_mfiltered, M11_mfiltered, M12_mfiltered,
          type = "html",
          out = "time_male_3.html",
          title = "Regression Results: Male Respondents")

#####Age Subset#####
#####With controls
#####No weights

MTData_18_35 <- Data_male %>%
  mutate(
    AGE_num = suppressWarnings(as.numeric(AGE))  
  ) %>%
  filter(!is.na(AGE_num), dplyr::between(AGE_num, 18, 35))

summary(MTData_18_35$AGE_num)
range(MTData_18_35$AGE_num)

#Regression Models subset among men 18-35 

M__1_age <- lm(IRAQ_WAR_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__2_age <- lm(GAY_RIGHT_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__3_age <- lm(SUV_DESIRABILITY_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__4_age <- lm(SUV_PAY_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__5_age <- lm(DOMINANCE_scale ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__6_age <- lm(SYSTEM_JUSTIFICATION_rescaled  ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__7_age <- lm(CONSERVATISM_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__8_age <- lm(IMMIGRATION_rescaled  ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__9_age <- lm(MARIJUANA_rescaled  ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__10_age <- lm(ELECTRIC_CAR_rescaled  ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__11_age <- lm(TRANS_RIGHT_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)
M__12_age <- lm(HIRINGPOLICY_WOMEN_rescaled ~ P_EXP + IDEO + EDUC5, data=MTData_18_35)

#Export to Word document 
# === TABLE ===
stargazer(M__1_age, M__2_age, M__3_age, M__4_age, M__5_age, M__6_age,
          type = "html",
          out = "age subset.html",
          title = "Regression Results:Subset to Men Ages 18-35")

stargazer(M__7_age, M__8_age, M__9_age, M__10_age, M__11_age, M__12_age,
          type = "html",
          out = "age subset2.html",
          title = "Regression Results:Subset to Men AGes 18-35")